package com.link2room.cms.controller.api;

import com.link2room.cms.dto.param.base.CmsBaseParamDto;
import com.link2room.cms.dto.result.CmsBaseDto;
import com.link2room.cms.facade.ICmsBaseFacadeService;
import com.link2room.common.dto.result.base.BaseResultDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author sqj88
 * @date 2017/12/1 16:14
 */
@Api(tags= "cms栏位")
@RestController
@RequestMapping(value = "/api/CmsBases")
public class CmsBaseApiController {
    @Resource
    private ICmsBaseFacadeService cmsBaseFacadeService;

    @ApiOperation(value = "获取栏目树", response = CmsBaseDto.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name="parentCode",value="栏位主代码",dataType="String", paramType = "query",example="ROOT"),
            @ApiImplicitParam(name="groupType",value="位置类型",dataType="String", paramType = "query"),
            @ApiImplicitParam(name="isHalt",value="是否停用",dataType="String", paramType = "query")})
    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto cmsBaseTree(
            @RequestParam(value = "parentCode" ,required = false) String parentCode,
            @RequestParam(value = "groupType" ,required = false) String groupType,
            @RequestParam(value = "isHalt" ,required = false) String isHalt
    ) throws Exception {
        CmsBaseParamDto cmsBaseParamDto=new CmsBaseParamDto();
        cmsBaseParamDto.setParentCode(parentCode);
        cmsBaseParamDto.setGroupType(groupType);
        cmsBaseParamDto.setIsHalt(isHalt);
        List<CmsBaseDto> cmsBaseTree = cmsBaseFacadeService.getCmsBaseTree(cmsBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setListToQueryResult(cmsBaseTree);
        return l2rRs;
    }

    @ApiOperation(value = "获取栏目详情", response = CmsBaseDto.class)
    @ApiImplicitParam(name="id",value="栏位ID",dataType="Long", paramType = "path",example="12")
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public BaseResultDto cmsBase(
            @PathVariable("id") Long id
    ) throws Exception {
        CmsBaseParamDto cmsBaseParamDto=new CmsBaseParamDto();
        cmsBaseParamDto.setId(id);
        CmsBaseDto cmsBaseDto = cmsBaseFacadeService.getCmsBaseDto(cmsBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(cmsBaseDto);
        return l2rRs;
    }

    @ApiOperation(value = "获取栏目详情", response = CmsBaseDto.class)
    @ApiImplicitParam(name="id",value="栏位ID",dataType="Long", paramType = "path",example="12")
    @RequestMapping(value = "/CmsBase",method = RequestMethod.GET)
    public BaseResultDto cmsBase(
            @RequestParam(value = "categoryCode",required = true) String categoryCode
    ) throws Exception {
        CmsBaseParamDto cmsBaseParamDto=new CmsBaseParamDto();
        cmsBaseParamDto.setCategoryCode(categoryCode);
        CmsBaseDto cmsBaseDto = cmsBaseFacadeService.getCmsBaseDtoByCode(cmsBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(cmsBaseDto);
        return l2rRs;
    }
}
